<template>
	<!--新增界面-->
	<el-dialog v-loading.fullscreen.lock="loading" element-loading-text="处理中......" title="新增责任" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off" :top="dialog_margin_top">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-col :span="12">
		  		<!-- 移除原因：点击保存时才生成责任代码 -->
		  		<!-- <el-form-item label="标的/责任代码" required>
		  							<el-input v-model="formData.itemcode" readonly size="small"></el-input>
		  						</el-form-item> -->
				<el-form-item label="责任中文名称" required>
					<el-input v-model="formData.itemcname"size="small"></el-input>
				</el-form-item>
				<el-form-item label="责任英文名称">
					<el-input v-model="formData.itemename"size="small"></el-input>
				</el-form-item>
				<el-form-item label="关联险种">
					<el-select v-model="formData.risks"  placeholder="险种代码" multiple value-key="riskcode" filterable size="small" style="width:100%">
						<el-option v-for="item in riskOptions" :key="item.riskcode" :label="item.riskcode + '-' + item.riskcname" :value="item"></el-option>
					</el-select>
				</el-form-item>
		  	</el-col>
		  	<el-col :span="12">
				<el-form-item label="生效日期">
					<el-date-picker type="date" placeholder="选择日期" v-model="formData.startdate" style="width: 100%;" :editable="false" size="small"></el-date-picker>
				</el-form-item>
				<el-form-item label="失效日期">
					<el-date-picker type="date" placeholder="选择日期" v-model="formData.enddate" style="width: 100%;" :editable="false" size="small"></el-date-picker>
				</el-form-item>
				<el-form-item label="责任状态">
					<el-select v-model="formData.validstatus" size="small" disabled>
						<el-option v-for="item in validOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="责任层级" required>
					<el-select v-model="formData.id" size="small">
						<el-option v-for="level in levelOptions" :key="level.value" :label="level.label" :value="level.value"></el-option>
					</el-select>
				</el-form-item>
		  	</el-col>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="warning" @click="add">保 存</el-button>
		  </span>
	</el-dialog>
</template>

<script>

import ItemAPI from "../../../../js/production/item/itemAPI"
import RiskAPI from "../../../../js/production/risk/riskAPI";

  export default {
	data() {
		return {
			dialog_margin_top: '5%',
			dialogVisible: true,
			formData: {
			        itemcode: '',
		                    itemcname: '',
		                    itemename: '',
		                    startdate: '',
		                    enddate: '',
		                    validstatus: '1',
		                    id: '2',
		                    kind: {},
		                    risks : [],
			},
			validOptions: [
				{label : '1-有效',value: '1'},
				{label : '0-无效',value: '0'}
			],
			levelOptions: [
				{label : '1级责任',value: '0'},
				{label : '2级责任',value: '1'},
				{label : '无层级',value: '2'},
			],
			loading :false,
			riskOptions : [],
		}
	},
	mounted() {
		RiskAPI.initRiskSelect(this);
		ItemAPI.generateItemCode(this);
		this.formData.kind = this.$parent.kind;
	},
	methods: {
		add() {
			if('undefined' != typeof(this.formData.startdate) && 'undefined' != typeof(this.formData.enddate) && this.formData.startdate != '' && this.formData.enddate != '') {
				if(this.formData.enddate < this.formData.startdate) {
					this.$message({type: 'error',message: '【失效日期】不能小于【生效日期】'});
					this.formData.enddate = '';
					return;
				}
			}
			ItemAPI.add(this);
		},
		off() {
			this.$parent.showAddDialog = false;
		}
	}
  }
</script>